package com.woniu.user.controller;

import com.woniu.common.pojo.Flower;
import com.woniu.common.pojo.Shops;
import com.woniu.common.vo.AjaxResult;
import com.woniu.user.service.CommodityService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/commodity")
@CrossOrigin
public class CommodityController {
    @Resource
    private CommodityService commodityService;

    @RequestMapping("findAll")
    public AjaxResult findAll(@RequestBody Shops shop) {
        List<Flower> findll = commodityService.findll(shop);
        System.out.println(findll);
        return AjaxResult.success("店铺商品如下:", findll);
    }

    @RequestMapping("delete")
    public AjaxResult delete(@RequestBody Flower flower) {
        commodityService.deleteFlower(flower);
        return AjaxResult.success("删除成功");
    }

    @RequestMapping("updateCommodity")
    public AjaxResult updateCommodity(@RequestBody Flower flower) {
        commodityService.updateCommodity(flower);
        return AjaxResult.success("修改成功");
    }

    @RequestMapping("addsCommodity")
    public AjaxResult addsCommodity(@RequestBody Flower flower) {
        commodityService.addsCommodity(flower);
        return AjaxResult.success("修改成功");
    }

    //    查询所有
    @RequestMapping("findAllFlower")
    public AjaxResult findAllFlower() {
        List<Flower> allFlower = commodityService.findll();
        for (Flower flower : allFlower) {
            System.out.println(flower);
        }
        return AjaxResult.success("查询成功", allFlower);
    }

    //    查询中秋爱情鲜花
    @RequestMapping("findMidAutumn")
    public AjaxResult findMidAutumn() {
        List<Flower> allFlower = commodityService.findMidAutumn();
        for (Flower flower : allFlower) {
            System.out.println(flower);
        }
        return AjaxResult.success("查询成功", allFlower);
    }

    //    查询新品鲜花
    @RequestMapping("findNew")
    public AjaxResult findNew() {
        List<Flower> allFlower = commodityService.findNew();
        for (Flower flower : allFlower) {
            System.out.println(flower);
        }
        return AjaxResult.success("查询成功", allFlower);
    }

    //    查询爱情鲜花
    @RequestMapping("findLove")
    public AjaxResult findLove() {
        List<Flower> allFlower = commodityService.findLove();
        for (Flower flower : allFlower) {
            System.out.println(flower);
        }
        return AjaxResult.success("查询成功", allFlower);
    }

    //    查询生日鲜花
    @RequestMapping("findBirthday")
    public AjaxResult findBirthday() {
        List<Flower> allFlower = commodityService.findBirthday();
        for (Flower flower : allFlower) {
            System.out.println(flower);
        }
        return AjaxResult.success("查询成功", allFlower);
    }

    //    根据鲜花类型的id查询数据
    @GetMapping("/findFlowerByTypeId")
    public AjaxResult findFlowerByTypeId(@RequestParam("tid") Integer tid) {
        System.out.println("想要查询的id是" + tid);
        List<Flower> allFlower = commodityService.findType(tid);
        return AjaxResult.success("查询成功", allFlower);
    }
}
